<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Item
 *
 * @mixin \Eloquent
 * @property int $id
 * @property string|null $name
 * @property string|null $city 城市
 * @property \Carbon\Carbon|null $created_at
 * @property string|null $deleted_at
 * @property int|null $craftmans_id 小组ID
 * @property string|null $overed_at 项目结束时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereCraftmansId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereOveredAt($value)
 * @property string|null $province 省
 * @property \Carbon\Carbon|null $updated_at
 * @property-read mixed $real_city
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereProvince($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Item whereUpdatedAt($value)
 */
class Item extends Model
{
    protected $appends = ['real_city'];
    protected $guarded = [];

    public function getRealCityAttribute()
    {
        $res = Area::whereId($this->attributes['city'])->first();
        if ($res == null || $res->name=='市辖区'){
            return Area::whereId($this->attributes['province'])->first()->name;
        }
        return $res->name;
    }

    public function inssertAll($data)
    {
        return \DB::table($this->getTable())->insert($data);
    }
}
